package com.glory.dmegcpda.customView

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.Gravity
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import java.util.*

/**
 * FileName: ListLinearLayout
 * Author: XJH
 * Date: 2021/5/14 15:39
 * Description:
 * History:
 */
class ListLinearLayout @JvmOverloads constructor(context: Context?, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : LinearLayout(context, attrs, defStyleAttr) {
    private var content: List<String> = ArrayList()
    fun setContent(content: List<String>) {
        this.content = content
        if (content.isNotEmpty()) {
            for (s in content) {
                val tv = TextView(context)
                val params = LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT)
                params.weight = 1f
                tv.layoutParams = params
                tv.gravity = Gravity.CENTER
                tv.setTextColor(Color.WHITE)
                tv.text = s
                this.addView(tv)
            }
        }
    }

    private fun init() {
        this.orientation = HORIZONTAL
    }

    init {
        init()
    }
}